<template>
  <div :class="{fixed:fixed}">
    <div class="title">分类</div>
    <Card>
      <div class="side">
        <div class="item">
          <nuxt-link to="/">
            <span class="icon el-icon-house"></span>首页
          </nuxt-link>
        </div>
        <div v-for="item in category" class="item" :key="item.id">
          <nuxt-link :to="{name:'node',params:{id:item.id}}">
            <span :class="'icon '+item.icon"></span>
            <span v-text="item.title"></span>
          </nuxt-link>
        </div>
      </div>
    </Card>
    <div class="title">客户端</div>
    <Card>
      <div class="side">
        <div class="item">
          <el-link href="https://apps.apple.com/il/app/%E7%8C%BF%E5%A0%86%E5%A0%86/id6443633238" target="_blank">
            iOS
          </el-link>
        </div>
        <div class="item">
          <el-link href="https://apps.apple.com/cn/app/simple%E7%A4%BE%E5%8C%BA/id1630714801?mt=12" target="_blank">
            macOS
          </el-link>
        </div>
      </div>
    </Card>
  </div>
</template>

<script>

export default {
  name: "side",
  props:{
    category:{
      type:Array,
      default:()=>[]
    },
  },
  data() {
    return {
      //是否浮动
      fixed: false
    };
  },
  mounted() {
    //监听滚动条
    window.addEventListener("scroll", this.handleScroll);
  }
  , methods: {
    getScrollTop() {
      var scroll_top = 0;
      if (document.documentElement && document.documentElement.scrollTop) {
        scroll_top = document.documentElement.scrollTop;
      } else if (document.body) {
        scroll_top = document.body.scrollTop;
      }
      return scroll_top;
    },
    handleScroll(event) {
      let top = this.getScrollTop();
      if (top > 8) {
        this.fixed = true;
      } else {
        this.fixed = false;
      }
    }
  }
}
</script>

<style scoped lang="less">
.side {
  .title{
    padding-left: 10px;
    font-size: 16px;
    font-weight: 400;
    color: var(--post-color);
  }
  .item {
    height: 35px;
    line-height: 35px;
    margin-bottom: 10px;
    color: var(--text-color);
    //背景颜色过渡
    transition: background-color 0.3s;
    //圆角
    border-radius: 5px;

    .icon {
      margin-right: 10px;
    }

    &:hover {
      background-color: var(--hover-bg-color);
    }
  }
}

.fixed {
  position: fixed;
  top: 80px;
  width: 160px;
  //left: 0;
  //right: 0;
  z-index: 100;
}
</style>
